import { _decorator, Button, Component, Label, Node, ProgressBar, tween } from 'cc';
import Utils from '../../utils/Utils';
import { AudioManager } from '../../game/AudioManager';
const { ccclass, property } = _decorator;

@ccclass('BeginItem')
export class BeginItem extends Component {
    @property(Node) hand: Node = null;
    @property(Button) btn_start: Button = null;
    @property(ProgressBar) progressBar: ProgressBar = null;
    @property(Label) lbl_progress: Label = null;

    public timeOutCb: Function = null;

    start() {
        this.btn_start.node.on(Button.EventType.CLICK, () => {
            AudioManager.Instance.playUIClick();
            this.timeOutCb?.();
        }, this);

        Utils.AutoScale(this.hand);
        Utils.AutoUpDown(this.btn_start.node);
        this.progressBar.progress = 0;
        this.lbl_progress.string = '0%';
        tween(this.progressBar)
            .to(5, { progress: 1 }, {
                onUpdate: () => {
                    const percent = Math.floor(this.progressBar.progress * 100);
                    this.lbl_progress.string = percent + '%';
                }
            })
            .call(() => {
                this.lbl_progress.string = '100%';
                // this.timeOutCb?.();
            })
            .start();
    }
}


